package com.chen.naisimall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认需要用的数据
 * @author woita
 */
public class OrderConfirmVo {

    //收货地址ums_member-receive-address表
    @Getter @Setter
    List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter @Setter
    List<OrderItemVo> items;

    //发票记录

    //优惠券信息
    @Getter @Setter
    Integer integration;

    //订单总额
    //BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal totalNum = BigDecimal.ZERO;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                //计算当前商品的总价格
                BigDecimal itemPrice = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                //再计算全部商品的总价格
                totalNum = totalNum.add(itemPrice);
            }
        }
        return totalNum;
    }

    //应付价格
    //BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    @Setter @Getter
    Map<Long, Boolean> stocks;

    //防重令牌
    @Setter @Getter
    String orderToken;

    public Integer getCount(){
        Integer count = 0;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }
}
